/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.sensor;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import org.netbeans.api.visual.model.ObjectState;
import org.netbeans.api.visual.widget.Scene;
import org.netbeans.api.visual.widget.Widget;

/**
 *
 * @author Timon Veenstra
 */
public class CircleWidget extends Widget {

    private int r;

    public CircleWidget(Scene scene, int radius) {
        super(scene);
        r = radius;
    }

    @Override
    protected void notifyStateChanged(ObjectState previousState, ObjectState state) {
        if (state.isHovered()) {
            setForeground(Color.GREEN);
        }
        if (previousState.isHovered()) {
            setForeground(Color.BLUE);
        }
    }



    @Override
    protected Rectangle calculateClientArea() {
        return new Rectangle(-r, -r, 2 * r + 1, 2 * r + 1);
    }

    @Override
    protected void paintWidget() {
        Graphics2D g = getGraphics();
        g.setColor(getForeground());
        g.drawOval(-r, -r, 2 * r, 2 * r);
    }
}
